package com.wenyu.wenyuyuedu.adapter.circleAdapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.wenyu.wenyuyuedu.R;
import com.wenyu.wenyuyuedu.bean.SearchActivityBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 搜索结果的书圈
 * Created by lenovo on 2017/3/14.
 */

public class SearchResultListViewAdapter extends BaseAdapter {
    private List<SearchActivityBean.CircleBean> mCircleList = new ArrayList<>();
    private Context context;
    private View view;

    public SearchResultListViewAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getCount() {
        return mCircleList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        MyCircleHolder holder = null;
        if (view == null) {
            holder = new MyCircleHolder();
            view = View.inflate(context, R.layout.search_circle_item, null);
            holder.circle_image = (ImageView) view.findViewById(R.id.circle_image);
            holder.circle_name = (TextView) view.findViewById(R.id.circle_name);
            view.setTag(holder);
        } else {
            holder = (MyCircleHolder) view.getTag();
        }
        Glide.with(context)
                .load(mCircleList.get(i).getCover())
                .error(R.drawable.login_logo)
                .placeholder(R.drawable.login_logo)
                .into(holder.circle_image);
        holder.circle_name.setText(mCircleList.get(i).getTitle());
        return view;
    }

    class MyCircleHolder {
        ImageView circle_image;
        TextView circle_name;
    }

    public void addAll(List<SearchActivityBean.CircleBean> circleList) {
        mCircleList = circleList;
        notifyDataSetChanged();
    }

}
